#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline long long qmi(long long a,int b)
{
	long long res = 1;
	while(b)
	{
		if(b & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		b >>= 1;
	}
	return res;
}
char mp[3003][3003];
int n,k;
struct{
	#define lowbit(x) ((x)&-(x))
	bool b[1<<25|3];
	int cnt[1<<25|3];
	int dui[7][7];
	void Solve()
	{
		int m = 0;
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++)
				dui[i][j] = m++;
		for(int i = 0;i <= n + 1;i++)
			for(int j = 0;j <= n + 1;j++) if(!dui[i][j])
				dui[i][j] = m;
		dui[1][1] = 0;
		int T = 0;
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++) if(mp[i][j] == '#')
				T |= (1 << dui[i][j]);
		b[T] = 1;
		int ans = 0;
		for(int S = 1;S < (1 << m);S++)
			cnt[S] = cnt[S ^ lowbit(S)] + 1;
		for(int S = T + 1;S < (1 << m);S++) if((S & T) == T)
		{
			if(cnt[S] > cnt[T] + k) continue;
			bool f = 0;
			for(int i = 1;i <= n && !f;i++)
				for(int j = 1;j <= n;j++) if((S & (1 << dui[i][j])) && b[S ^ (1 << dui[i][j])] && (S & ((1 << dui[i - 1][j]) | (1 << dui[i][j - 1]) | (1 << dui[i][j + 1]) | (1 << dui[i + 1][j]))))
				{
					f = 1;
					break;
				}
			ans += (f && cnt[S] == cnt[T] + k);
			b[S] = f;
		}
		cout << ans;
	}
}Sub0;
int w[3003][3003][3];
long long cnt[4],sg[4];
struct{
	void Solve()
	{
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++)
				if(mp[i][j] == '.' && (mp[i - 1][j] == '#' || mp[i][j - 1] == '#' || mp[i][j + 1] == '#' || mp[i + 1][j] == '#'))
					cnt[0] += (w[i][j][0] = 1);
		sg[0] = cnt[0];
	}
}Sub1;
struct{
	void Solve()
	{
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++) if(w[i][j][0])
				cnt[1] += (w[i][j][1] = sg[0] - w[i][j][0] - w[i - 1][j][0] - w[i][j - 1][0] - w[i + 1][j][0] - w[i][j + 1][0]);
		cnt[1] = cnt[1] / 2 % mod;
		sg[1] = cnt[1];
		for(int i = 1;i <= n;i++)
		{
			for(int j = 1;j <= n;j++) if(mp[i][j] == '.')
			{
				if(mp[i - 1][j] == '.' && (w[i][j][0] || w[i - 1][j][0]))
					cnt[1]++;
				if(mp[i][j - 1] == '.' && (w[i][j][0] || w[i][j - 1][0]))
					cnt[1]++;
			}
		}
		cnt[1] %= mod;
	}
}Sub2;
struct{
	void Solve()
	{
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++) if(w[i][j][0])
			{
				w[i][j][2] = (sg[1] + mod - w[i][j][1] - w[i - 1][j][1] - w[i][j - 1][1] - w[i + 1][j][1] - w[i][j + 1][1]) % mod;
				int c = w[i - 1][j][0] + w[i][j - 1][0] + w[i + 1][j][0] + w[i][j + 1][0];
				w[i][j][2] += c * (c - 1) / 2;
				cnt[2] += w[i][j][2];
			}
		cnt[2] = cnt[2] % mod * (mod + 1) / 3 % mod;
		sg[2] = cnt[2];
		for(int i = 3;i <= n;i++)
			for(int j = 1;j <= n;j++)
				if(mp[i][j] == '.' && mp[i - 1][j] == '.' && mp[i - 2][j] == '.' && (w[i - 2][j][0] || w[i - 1][j][0] || w[i][j][0]))
					cnt[2]++;
		for(int i = 1;i <= n;i++)
			for(int j = 3;j <= n;j++)
				if(mp[i][j] == '.' && mp[i][j - 1] == '.' && mp[i][j - 2] == '.' && (w[i][j - 2][0] || w[i][j - 1][0] || w[i][j][0]))
					cnt[2]++;
		for(int i = 2;i <= n;i++)
			for(int j = 2;j <= n;j++)
			{
				if(mp[i][j] == '.' && mp[i - 1][j] == '.' && mp[i][j - 1] == '.' && (w[i - 1][j][0] || w[i][j - 1][0] || w[i][j][0]))
					cnt[2]++;
				if(mp[i][j] == '.' && mp[i - 1][j] == '.' && mp[i - 1][j - 1] == '.' && (w[i - 1][j][0] || w[i - 1][j - 1][0] || w[i][j][0]))
					cnt[2]++;
				if(mp[i][j] == '.' && mp[i][j - 1] == '.' && mp[i - 1][j - 1] == '.' && (w[i][j - 1][0] || w[i - 1][j - 1][0] || w[i][j][0]))
					cnt[2]++;
				if(mp[i - 1][j - 1] == '.' && mp[i - 1][j] == '.' && mp[i][j - 1] == '.' && (w[i - 1][j - 1][0] || w[i - 1][j][0] || w[i][j - 1][0]))
					cnt[2]++;
			}
		for(int i = 1;i <= n;i++)
			for(int j = 1;j <= n;j++) if(mp[i][j] == '.')
			{
				if(mp[i - 1][j] == '.' && (w[i][j][0] || w[i - 1][j][0]))
					cnt[2] += sg[0] - w[i - 2][j][0] - w[i - 1][j - 1][0] - w[i - 1][j][0] - w[i - 1][j + 1][0] - w[i][j - 1][0] - w[i][j][0] - w[i][j + 1][0] - w[i + 1][j][0];
				if(mp[i][j - 1] == '.' && (w[i][j][0] || w[i][j - 1][0]))
					cnt[2] += sg[0] - w[i - 1][j - 1][0] - w[i - 1][j][0] - w[i][j - 2][0] - w[i][j - 1][0] - w[i][j][0] - w[i][j + 1][0] - w[i + 1][j - 1][0] - w[i + 1][j][0];
			}
		cnt[2] %= mod;
	}
}Sub3;
// struct{
// 	void Solve()
// 	{
// 		long long A = 0,B = 0,C = 0,D = 0,E = 0;
// 		for(int i = 3;i <= n;i++)
// 			for(int j = 1;j <= n;j++)
// 				if(mp[i][j] == '.' && mp[i - 1][j] == '.' && mp[i - 2][j] == '.' && (w[i - 2][j][0] || w[i - 1][j][0] || w[i][j][0]))
// 					A += sg[0] - w[i + 1][j][0] - w[i][j][0] - w[i][j - 1][0] - w[i][j + 1][0] - w[i - 1][j][0] - w[i - 1][j - 1][0] - w[i - 1][j + 1][0] - w[i - 2][j][0] - w[i - 2][j - 1][0] - w[i - 2][j + 1][0] - w[i - 3][j][0];
// 		for(int i = 1;i <= n;i++)
// 			for(int j = 3;j <= n;j++)
// 				if(mp[i][j] == '.' && mp[i][j - 1] == '.' && mp[i][j - 2] == '.' && (w[i][j - 2][0] || w[i][j - 1][0] || w[i][j][0]))
// 					A += sg[0] - w[i - 1][j][0] - w[i - 1][j - 1][0] - w[i - 1][j - 2][0] - w[i][j - 3][0] - w[i][j - 2][0] - w[i][j - 1][0] - w[i][j][0] - w[i][j + 1][0] - w[i + 1][j][0] - w[i + 1][j - 1][0] - w[i + 1][j - 2][0];
// 		for(int i = 2;i <= n;i++)
// 			for(int j = 2;j <= n;j++)
// 			{
// 				if(mp[i][j] == '.' && mp[i - 1][j] == '.' && mp[i][j - 1] == '.' && (w[i - 1][j][0] || w[i][j - 1][0] || w[i][j][0]))
// 					A += sg[0] - w[i - 2][j][0] - w[i - 1][j - 1][0] - w[i - 1][j][0] - w[i - 1][j + 1][0] - w[i][j - 2][0] - w[i][j - 1][0] - w[i][j][0] - w[i][j + 1][0] - w[i + 1][j - 1][0] - w[i + 1][j][0];
// 				if(mp[i][j] == '.' && mp[i - 1][j] == '.' && mp[i - 1][j - 1] == '.' && (w[i - 1][j][0] || w[i - 1][j - 1][0] || w[i][j][0]))
// 					A += sg[0] - w[i - 2][j - 1][0] - w[i - 2][j][0] - w[i - 1][j - 2][0] - w[i - 1][j - 1][0] - w[i - 1][j][0] - w[i - 1][j + 1][0] - w[i][j - 1][0] - w[i][j][0] - w[i][j + 1][0] - w[i + 1][j][0];
// 				if(mp[i][j] == '.' && mp[i][j - 1] == '.' && mp[i - 1][j - 1] == '.' && (w[i][j - 1][0] || w[i - 1][j - 1][0] || w[i][j][0]))
// 					A += sg[0] - w[i - 2][j - 1][0] - w[i - 1][j - 2][0] - w[i - 1][j - 1][0] - w[i - 1][j][0] - w[i][j - 2][0] - w[i][j - 1][0] - w[i][j][0] - w[i][j + 1][0] - w[i + 1][j - 1][0] - w[i + 1][j][0];
// 				if(mp[i - 1][j - 1] == '.' && mp[i - 1][j] == '.' && mp[i][j - 1] == '.' && (w[i - 1][j - 1][0] || w[i - 1][j][0] || w[i][j - 1][0]))
// 					A += sg[0] - w[i - 2][j - 1][0] - w[i - 2][j][0] - w[i - 1][j - 2][0] - w[i - 1][j - 1][0] - w[i - 1][j][0] - w[i - 1][j + 1][0] - w[i][j - 2][0] - w[i][j - 1][0] - w[i][j][0] - w[i + 1][j - 1][0];
// 			}
// 		A %= mod;
// 		for(int i = 1;i <= n;i++)
// 		{
// 			for(int )
// 		}
// 	}
// }Sub4;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("brick.in","r",stdin);
	freopen("brick.out","w",stdout);
	cin >> n >> k;
	for(int i = 1;i <= n;i++)
		for(int j = 1;j <= n;j++)
			cin >> mp[i][j];
	Sub1.Solve(),Sub2.Solve(),Sub3.Solve();
	if(k == 1)
		cout << cnt[0];
	else if(k == 2)
		cout << cnt[1];
	else if(k == 3)
		cout << cnt[2];
	else{
		// Sub4.Solve();
		// cout << cnt[3];
		Sub0.Solve();
	}
	cout << "\n";
	return 0;
}